/*********************************************************************
	Rhapsody	: 7.5.2
	Login		: dan
	Component	: TPkg_RobotController_Comp
	Configuration 	: DefaultConfig
	Model Element	: Sensor
//!	Generated Date	: Sat, 18, Dec 2010 
	File Path	: TPkg_RobotController_Comp/DefaultConfig/RobotPkg/Sensor.java
*********************************************************************/

package RobotPkg;

//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// RobotPkg/Sensor.java                                                                  
//----------------------------------------------------------------------------

//## package RobotPkg 


//## class Sensor 
public class Sensor implements RiJStateConcept, Animated, ISensor {
    
    public Reactive reactive;		//## ignore 
    
    protected int id;		//## attribute id 
    
    protected boolean line;		//## attribute line 
    
    protected RobotController itsRobotController;		//## link itsRobotController 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int on=1;
    public static final int seesLine=2;
    public static final int doesntSeeLine=3;
    public static final int off=4;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    protected int on_subState;		//## ignore 
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassSensor = new AnimClass("RobotPkg.Sensor",false);
    //#]
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  Sensor(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassSensor.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getId() 
    public int getId() {
        try {
            animInstance().notifyMethodEntered("getId",
               new ArgData[] {
               });
        
        //#[ operation getId() 
        return this.id;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getLine() 
    public boolean getLine() {
        try {
            animInstance().notifyMethodEntered("getLine",
               new ArgData[] {
               });
        
        //#[ operation getLine() 
        return this.line;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation read() 
    public boolean read() {
        try {
            animInstance().notifyMethodEntered("read",
               new ArgData[] {
               });
        
        //#[ operation read() 
        System.out.println("isLine?");    
        return false;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation setLine(boolean) 
    public void setLine(boolean line) {
        try {
            animInstance().notifyMethodEntered("setLine",
               new ArgData[] {
                   new ArgData(boolean.class, "line", AnimInstance.animToString(line))
               });
        
        //#[ operation setLine(boolean) 
        this.line = line;  
        itsRobotController.gen(new evLine(id, line));   
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public void setId(int p_id) {
        id = p_id;
    }
    
    //## auto_generated 
    public RobotController getItsRobotController() {
        return itsRobotController;
    }
    
    //## auto_generated 
    public void __setItsRobotController(RobotController p_RobotController) {
        itsRobotController = p_RobotController;
        if(p_RobotController != null)
            {
                animInstance().notifyRelationAdded("itsRobotController", p_RobotController);
            }
        else
            {
                animInstance().notifyRelationCleared("itsRobotController");
            }
    }
    
    //## auto_generated 
    public void _setItsRobotController(RobotController p_RobotController) {
        if(itsRobotController != null)
            {
                itsRobotController._removeItsSensor(this);
            }
        __setItsRobotController(p_RobotController);
    }
    
    //## auto_generated 
    public void setItsRobotController(RobotController p_RobotController) {
        if(p_RobotController != null)
            {
                p_RobotController._addItsSensor(this);
            }
        _setItsRobotController(p_RobotController);
    }
    
    //## auto_generated 
    public void _clearItsRobotController() {
        animInstance().notifyRelationCleared("itsRobotController");
        itsRobotController = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(on_subState == state)
                {
                    return true;
                }
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
            switch (rootState_subState) {
                case on:
                {
                    on_add(animStates);
                }
                break;
                case off:
                {
                    off_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case seesLine:
                {
                    res = seesLine_takeEvent(id);
                }
                break;
                case doesntSeeLine:
                {
                    res = doesntSeeLine_takeEvent(id);
                }
                break;
                case off:
                {
                    res = off_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public void on_add(AnimStates animStates) {
            animStates.add("ROOT.on");
            switch (on_subState) {
                case seesLine:
                {
                    seesLine_add(animStates);
                }
                break;
                case doesntSeeLine:
                {
                    doesntSeeLine_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void seesLine_add(AnimStates animStates) {
            animStates.add("ROOT.on.seesLine");
        }
        
        //## statechart_method 
        public void doesntSeeLine_add(AnimStates animStates) {
            animStates.add("ROOT.on.doesntSeeLine");
        }
        
        //## statechart_method 
        public void off_add(AnimStates animStates) {
            animStates.add("ROOT.off");
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
            on_subState = RiJNonState;
        }
        
        //## statechart_method 
        public void offEnter() {
        }
        
        //## statechart_method 
        public void seesLine_exit() {
            seesLineExit();
            animInstance().notifyStateExited("ROOT.on.seesLine");
        }
        
        //## statechart_method 
        public void seesLine_enter() {
            animInstance().notifyStateEntered("ROOT.on.seesLine");
            on_subState = seesLine;
            rootState_active = seesLine;
            seesLineEnter();
        }
        
        //## statechart_method 
        public void off_exit() {
            offExit();
            animInstance().notifyStateExited("ROOT.off");
        }
        
        //## statechart_method 
        public void offExit() {
        }
        
        //## statechart_method 
        public void doesntSeeLine_entDef() {
            doesntSeeLine_enter();
        }
        
        //## statechart_method 
        public void doesntSeeLineExit() {
        }
        
        //## statechart_method 
        public void onEnter() {
        }
        
        //## statechart_method 
        public int seesLineTakelineNotSeen() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("3");
            seesLine_exit();
            //#[ transition 3 
            setLine(false);
            //#]
            doesntSeeLine_entDef();
            animInstance().notifyTransitionEnded("3");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void doesntSeeLine_enter() {
            animInstance().notifyStateEntered("ROOT.on.doesntSeeLine");
            on_subState = doesntSeeLine;
            rootState_active = doesntSeeLine;
            doesntSeeLineEnter();
        }
        
        //## statechart_method 
        public int seesLineTakelineSeen() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("5");
            seesLine_exit();
            seesLine_entDef();
            animInstance().notifyTransitionEnded("5");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public int seesLine_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(lineNotSeen.lineNotSeen_RobotPkg_id))
                {
                    res = seesLineTakelineNotSeen();
                }
            else if(event.isTypeOf(lineSeen.lineSeen_RobotPkg_id))
                {
                    res = seesLineTakelineSeen();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = on_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public void on_exit() {
            switch (on_subState) {
                case seesLine:
                {
                    seesLine_exit();
                }
                break;
                case doesntSeeLine:
                {
                    doesntSeeLine_exit();
                }
                break;
                default:
                    break;
            }
            on_subState = RiJNonState;
            onExit();
            animInstance().notifyStateExited("ROOT.on");
        }
        
        //## statechart_method 
        public void on_entDef() {
            on_enter();
            
            animInstance().notifyTransitionStarted("7");
            doesntSeeLine_entDef();
            animInstance().notifyTransitionEnded("7");
        }
        
        //## statechart_method 
        public int doesntSeeLine_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(lineNotSeen.lineNotSeen_RobotPkg_id))
                {
                    res = doesntSeeLineTakelineNotSeen();
                }
            else if(event.isTypeOf(lineSeen.lineSeen_RobotPkg_id))
                {
                    res = doesntSeeLineTakelineSeen();
                }
            
            if(res == RiJStateReactive.TAKE_EVENT_NOT_CONSUMED)
                {
                    res = on_takeEvent(id);
                }
            return res;
        }
        
        //## statechart_method 
        public int doesntSeeLineTakelineSeen() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("4");
            doesntSeeLine_exit();
            //#[ transition 4 
            setLine(true);
            //#]
            seesLine_entDef();
            animInstance().notifyTransitionEnded("4");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int on_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evOnOff.evOnOff_RobotPkg_id))
                {
                    res = onTakeevOnOff();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public int offTakeevOnOff() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("1");
            off_exit();
            on_entDef();
            animInstance().notifyTransitionEnded("1");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void off_enter() {
            animInstance().notifyStateEntered("ROOT.off");
            rootState_subState = off;
            rootState_active = off;
            offEnter();
        }
        
        //## statechart_method 
        public void seesLineExit() {
        }
        
        //## statechart_method 
        public void onExit() {
        }
        
        //## statechart_method 
        public void doesntSeeLineEnter() {
        }
        
        //## statechart_method 
        public void on_enter() {
            animInstance().notifyStateEntered("ROOT.on");
            rootState_subState = on;
            onEnter();
        }
        
        //## statechart_method 
        public void rootState_exit() {
            switch (rootState_subState) {
                case on:
                {
                    on_exit();
                }
                break;
                case off:
                {
                    off_exit();
                }
                break;
                default:
                    break;
            }
            rootState_subState = RiJNonState;
            rootStateExit();
            animInstance().notifyStateExited("ROOT");
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            animInstance().notifyTransitionStarted("0");
            off_entDef();
            animInstance().notifyTransitionEnded("0");
        }
        
        //## statechart_method 
        public int off_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evOnOff.evOnOff_RobotPkg_id))
                {
                    res = offTakeevOnOff();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int doesntSeeLineTakelineNotSeen() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("6");
            doesntSeeLine_exit();
            doesntSeeLine_entDef();
            animInstance().notifyTransitionEnded("6");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int onTakeevOnOff() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("2");
            on_exit();
            off_entDef();
            animInstance().notifyTransitionEnded("2");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void doesntSeeLine_exit() {
            doesntSeeLineExit();
            animInstance().notifyStateExited("ROOT.on.doesntSeeLine");
        }
        
        //## statechart_method 
        public void seesLineEnter() {
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public void off_entDef() {
            off_enter();
        }
        
        //## statechart_method 
        public void seesLine_entDef() {
            seesLine_enter();
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return Sensor.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassSensor; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
        msg.add("line", line);
        msg.add("id", id);
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsRobotController", false, true, itsRobotController);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(Sensor.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            Sensor.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            Sensor.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: TPkg_RobotController_Comp/DefaultConfig/RobotPkg/Sensor.java
*********************************************************************/

